package cn.edu.scau.cmi.wuzhenxin.singleton;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import javafx.scene.*;
import java.util.HashSet;
import java.util.Set;

public class MyController {
	@FXML
    private Button btn_single;
	
	@FXML
    private Button btn_mul;
	
    @FXML
    private TextField text_single;
    
    @FXML
    private TextField text_mul;
    
    @FXML
    private Text result_single;
    
    @FXML
    private Text result_mul;
    
    private Set<Marshall> Set = new HashSet<Marshall>();
    
    public void eventButton1(){	//单例模式
    	Chairman chairman = Chairman.getInstance(text_single.getText());
        	result_single.setText("结果:\n"+"已竞选完毕，当前主席为 ：" + chairman.getName());  
    }
    
    public void eventButton2(){	//多例模式
    	String result = "";
    	boolean flag = true;
    	if(Set.size()==10) {
    		result = "《《《兄弟，已经凑齐十大元帅了》》》：\n" ;
    	}
    	for(Marshall marshall : Set) {
    		if(text_mul.getText().equals(marshall.getName())) {
    			result = "《《《兄弟，别重复输入啊》》》：\n" ;
    			flag = false;
    			break;
    		}
    	}
    	if(flag) {
    				Set = Marshall.addInstance(text_mul.getText());
    	int count = 0;
    	for(Marshall marshall : Set) {
    		result += (++count)+" :";
    		result += marshall.getName();
    		result += "\n";
    	}
    	}
    	result_mul.setText(result);
    }

}
